//
//  GAKKIHUD+CustomDemo.m
//  GANGAIKit
//
//  Created by fh on 2019/11/6.
//  Copyright © 2019 cashchina. All rights reserved.
//

#import "GAKKIHUD+CustomDemo.h"
#import <MBProgressHUD/MBProgressHUD.h>
#import "CustomHUDView.h"

@interface GAKKIHUD ()
/** 自定义指示器demo */
@property (nonatomic, strong) MBProgressHUD *customHud;
@end

/// 一个自定义demo例子
@implementation GAKKIHUD (CustomDemo)

/// 显示等待上传框
- (void)showUploadProgress {
    [self hiddenUploadProgress];
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].delegate.window animated:YES];
    [self inner_custom_commonMBProgressHUDConfigurationWithHub:hud];
    hud.mode = MBProgressHUDModeCustomView;
    CustomHUDView *custom = [[CustomHUDView alloc] init];
    hud.customView = custom;
    hud.detailsLabel.text = @"正在等待上传...";
    self.customHud = hud;
}

/// 显示当前上传状态提醒
/// @param sectionTitle 分区头部标题
/// @param totalCount 总上传个数
/// @param currentIndex 当前上传的下标
- (void)setProgressWithSectionTitle:(NSString *)sectionTitle totalCount:(NSUInteger)totalCount currentIndex:(NSUInteger)currentIndex {
    self.customHud.detailsLabel.text = [NSString stringWithFormat:@"正在上传%@... 第%ld/%ld个... 请勿退出!",sectionTitle,currentIndex,totalCount];
    CustomHUDView *customView = (CustomHUDView *)self.customHud.customView;
    [customView.uploadProgressView setProgress:(currentIndex/(totalCount + 0.0)) animated:YES];
}

/// 设置上传速度和上传剩余时间
/// @param uploadSpeed 上传速度
/// @param uploadTime 上传剩余时间
- (void)setUploadStatusWithUploadSpeed:(NSString *)uploadSpeed uploadTime:(NSString *)uploadTime {
    CustomHUDView *customView = (CustomHUDView *)self.customHud.customView;
    customView.uploadSpeedLabel.text = uploadSpeed;
    customView.uploadTimeLabel.text = uploadTime;
}

/// 隐藏上传提示框
- (void)hiddenUploadProgress {
    [self.customHud removeFromSuperview];
    self.customHud = nil;
}

/// 公用配置
/// @param hud 控件
- (void)inner_custom_commonMBProgressHUDConfigurationWithHub:(MBProgressHUD *)hud {
    hud.bezelView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.8]; //0.45
    hud.minSize = CGSizeMake(120, 80);
    hud.detailsLabel.textColor = [UIColor whiteColor];
    hud.detailsLabel.font = [UIFont systemFontOfSize:17.0f];
    hud.removeFromSuperViewOnHide = YES;
}

@end
